home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / fish / 676-700 / 696 / ifslab / ifslab.doc < prev    next >
Text File  |  1995-03-18  |  43KB  |  875 lines

  1. /*******************************************************************\
  2. *                                                                   *
  3. *   IFS Lab - Iterated Function System Encoding/Rendering Program.  *
  4. *                                                                   *
  5. *         Written by Nathan Zeldes, 16 Bet Hakerem St.,             *
  6. *                   Jerusalem 96343, Israel.                        *
  7. *                                                                   *
  8. *    Copyright (C) 1992 by Nathan Zeldes. All Rights Reserved.      *
  9. *                                                                   *
  10. *     PROGRAM DOCUMENTATION     Version 1.0,  June 24, 1992         *
  11. *                                                                   *
  12. *                                                                   *
  13. \*******************************************************************/
  14.  
  15. NOTE:  This program uses the file requester in the freeware requester
  16. library written by C.W. Fox and Bruce Dawson.  The library file,
  17. req.library, should be placed in your libs: directory.  If req.library
  18. is missing, the program will still run but file I/O will be disabled.
  19.  
  20.  
  21. =========================
  22. Contents of this Doc File
  23. =========================
  24.  
  25.  
  26. Part I. Copyright and Distribution
  27.  
  28.  
  29. Part II. User Documentation
  30.  
  31.  1. Quick Start
  32.  
  33.  2. Overview
  34.  3. Nomenclature
  35.  4. Program Operation philosophy
  36.  5. Outline Editor Mode Operation
  37.  6. Collage Editor Mode Operation
  38.  7. Rendering Mode Operation
  39.  8. File I/O Operation
  40.  
  41.  
  42. Part III. Programmer Notes
  43.  
  44.  1. Coordinate system and Coefficient Ranges
  45.  2. Screens and Windows
  46.  3. Outline/Collage Window Colour Scheme
  47.  4. Gadget ID's
  48.  5. Outline Editor
  49.  6. Piece Storage
  50.  7. Collage Display mechanics
  51.  8. Coefficients Window issues
  52.  9. Rendering Mechanics
  53.  10. Compilation and Linking
  54.  11. Known Bugs
  55. ==================================
  56. Part I. Copyright and Distribution
  57. ==================================
  58.  
  59.  
  60. IFSLab is Copyright (C) 1992 by Nathan Zeldes, 16 Bet Hakerem St.,
  61. Jerusalem 96343, Israel.
  62.  
  63. This program is made available in the hope that it will give enjoyment to Amiga
  64. users.  Permission is granted to freely use and distribute IFSLab subject to
  65. the following conditions:
  66.  
  67.   a.  No profit is made on it in any way.  Nominal charges to cover cost of
  68.      media, duplication, shipping, online services, etc are allowed.
  69.   b. The package is distributed in its complete form, consisting of the source
  70.      (files IFSLab.c and IFSLab.h), the executable (IFSLab), this documentation
  71.      file (IFSLab.doc), the requester library files req.library and req.readme,
  72.      and the IFS code files in the subdirectory IFScodes.
  73.   c. None of the files is modified in any way without the written permission of
  74.      the author.
  75.   d. Inclusion of IFSLab in any commercial product is not permitted without the
  76.      written permission of the author.
  77.  
  78. DISCLAIMER:  Although it has been tested extensively, IFSLab is provided
  79.   "as is", without warranty of any kind.  In no event will the author be liable
  80.   for any direct or indirect damage or loss resulting from the use or misuse of
  81.   this program.
  82.  
  83.  
  84. ACKNOWLEDGEMENTS
  85.  
  86. The IFS method has been developed by Dr. Michael Barnsley (see references in
  87. Overview section below).
  88.  
  89. Thanks to C.W. Fox and Bruce Dawson for the file requester from their excellent
  90. freeware requester library for the Amiga.
  91. ===========================
  92. Part II. User Documentation
  93. ===========================
  94.  
  95.  
  96. 1. Quick Start
  97. --------------
  98.  
  99. Part II of this doc file contains detailed instructions. If you want to get the
  100. full benefit from this program, you should read it all.  The present section is
  101. for the impatient and/or knowledgeable, who want to try the program out right
  102. away!
  103.  
  104. To run IFSLab, you should first copy the file req.library to your libs:
  105. directory (if you don't have it there already).  If you don't, you will still
  106. be able to run IFSLab, but without the ability to load or save files.
  107.  
  108. Start IFSLab by double clicking its icon, or by typing its name in the Shell or
  109. CLI.  Now select the HELP item from the ABOUT menu, and read the brief
  110. instructions it will give you on-screen.  Then select the DEMO item from the
  111. ABOUT menu.  This will launch a demo of generation of the Sierpinski Triangle,
  112. and illustrate the operation of the program.
  113.  
  114. Next you may want to load some IFS codes by the PROJECT/LOAD FILE/IFS menuitem;
  115. some interesting codes found by the author and by others are in the directory
  116. 'IFScodes'.  When a code has been loaded, select the RENDER/START menuitem to
  117. render its attractor.  After you've tried the codes in the files, you're on
  118. your own - try to build your own IFS codes (here you will probably HAVE to read
  119. the instructions), and have fun!
  120.  
  121.  
  122. 2. Overview
  123. -----------
  124.  
  125. This program implements the IFS algorithm described by Barnsley and Sloan to
  126. allow the design and rendering of fractals in a user-friendly environment.  It
  127. provides for the convenient sketching of approximate image outlines by a
  128. paint-program-like mouse-driven user interface, and for definition of IFS Codes
  129. either from a mouse-driven Collage editor or by numeric entry from the
  130. keyboard.  The Attractors of the resultant IFS Codes can be rendered in black
  131. and white or in grayscale, in a user-defined resolution.  Outlines, IFS Codes
  132. and rendered Images can be saved to or read from disk.  The program has a very
  133. flexible IFS loader, which can read IFS code files generated by most other IFS
  134. programs, extracting the relevant codes and converting them as necessary to fit
  135. this program's conventions.  On reading in a file, or at the user's command at
  136. any time, the program will generate a collage for the current IFS (using its
  137. attractor as the Outline).  A facility for modifying an IFS to fit in the full
  138. screen size is also provided.
  139.  
  140. For more detailed information on the theory and use of IFS, refer to:
  141.  
  142.  a. M. Barnsley and A. Sloan:  A Better Way to Compress Images, BYTE, Jan.  88.
  143.  b. H.O. Peitgen and D. Saupe, eds.:  The Science of Fractal Images, Chapter 5.
  144.     Springer-Verlag, 1988.
  145.  c. M.Barnsley:  Fractals Everywhere, Academic Press, 1988.
  146.  
  147. 3. Nomenclature
  148. ---------------
  149.  
  150. In this document and program, the following terminology is used:
  151.  
  152. * Outline - a rough sketch of the fractal-to-be, used as the basis for the
  153.   reduced images that form the Collage.
  154.  
  155. * Transformation - a contractive affine transformation.
  156.  
  157. * IFS (Iterated Function System), used interchangeably with 'IFS Code' -
  158.   a set of N Transformations and their associated probabilities.
  159.  
  160. * Attractor - the exact fractal image represented by the IFS.
  161.  
  162. * Density - A parameter assigned to each transformation which describes
  163.   its probability per unit area, i.e. how bright it will appear in the
  164.   rendering process relative to the other transformations. See details in
  165.   section 5, "Collage Editor Mode Operation", under "Definition of Piece
  166.   Probabilities".
  167.  
  168. * Collage - an IFS, represented graphically as an overlay of the Transformed
  169.   Outlines on the original Outline.
  170.  
  171. * Piece - A single transformed image of the outline.  The Collage is made from
  172.   a set of up to 20 Pieces, representing the transformations in the IFS.
  173.  
  174. * Image - the reconstructed image (Attractor), as rendered from the IFS using
  175.   the random iteration algorithm.
  176.  
  177. * Coordinate Convention: The Top Left corner of the display area is defined as
  178.   the Origin, (0,0), with the positive X axis going to the right and the 
  179.   positive Y axis going downward. The full display area is defined as 1 unit
  180.   in width and 0.6775 units in height (for purposes of the translation
  181.   coefficients). This convention makes the rectangular window used for editing
  182.   represent the top 2/3 (approximately) of a 1x1 square area in the Real plane.
  183.  
  184.  
  185. 4. Program Operation philosophy
  186. -------------------------------
  187.  
  188. IFS Lab differs from some other IFS programs in that it focuses on the Collage
  189. Theorem, i.e.  on the fact that in an IFS, the attractor is covered exactly by
  190. its transformed copies.  Thus, IFS Lab will allow you to create the Collage
  191. directly, Jigsaw-puzzle style, from actual reduced/deformed images of the
  192. Outline that you can manipulate graphically with the mouse.  The program will
  193. also create an exact collage (with the Optimize function), and when reading in
  194. an IFS Code file, will create a Collage for the loaded codes.
  195.  
  196. Another difference is that IFS Lab uses a FIXED window in the Real plane to
  197. draw in (See above, "Coordinate Convention").  Therefore, no use is made of
  198. offset and scaling factors during rendering; the IFS code has to represent an
  199. attractor that falls within this fixed window.  This is mostly irrelevant to
  200. the user, since the OPTIMIZE function provided can modify any IFS codes
  201. violating this requirement (mainly those read in from disk files generated by
  202. other IFS programs, or copied from the literature) so that they will in fact
  203. obey it.
  204.  
  205. This program deals with 3 types of Objects:
  206.  
  207. a.  Outline.  This is a rough line sketch of the approximate image, the one to
  208. be reduced and transformed in the Collage operation.  It can be drawn in
  209. Outline Editor mode by the user, or loaded from a disk file.  An outline must
  210. exist when the program is in Collage Editor mode; if the user fails to draw or
  211. load it, the program will provide a default outline ("Happy Face" image) when
  212. the user enters the Collage Editor mode.  The outline is displayed onscreen as
  213. a one-colour image, and can be saved to disk as an IFF one-bitplane ILBM file.
  214. In Collage Editor mode, the user can specify (by the Optimize menuitem) that
  215. the current IFS code be used to generate automatically a full-screen Collage;
  216. this will use the Attractor of the IFS as an Outline.
  217.  
  218. b.  IFS.  This is a collection of between 1 and 20 affine transformations of
  219. the outline.  The IFS can be displayed by the program as a collage overlay on
  220. the screen, or as the transformations' coefficients themselves, displayed in a
  221. table.  The IFS coefficients can be saved to a disk file; such a file can be
  222. loaded from disk, at which point the loaded coefficients are converted
  223. immediately to a collage of their own attractor.
  224.  
  225. c.  Image.  This is the Attractor of the current IFS, and can be rendered in a
  226. user-specified resolution and depth.  The image can then be saved to an ILBM
  227. file.  The image occupies its own screen and can be brought to the front at any
  228. time by the depth gadgets or by a menu selection.  It is erased if a new image
  229. file is loaded or if a new rendering operation is started.
  230.  
  231. The program has three main modes or environments:
  232.  
  233. a. Outline Editor mode:
  234.   Permits the user to draw the approximate outline of the fractal by mouse.
  235.   Includes Freestyle draw, Lines, Erase and Fill functions.
  236.  
  237. b. Collage Editor mode:
  238.   Permits the mouse-driven generation of the transformed images (of the
  239.   outline) that are placed onto the outline, from which the IFS transformation
  240.   codes are computed by the program.  Attractor rendering is initiated from
  241.   this mode.
  242.  
  243. c. Rendering mode:
  244.   Here the Attractor of the current IFS is reconstructed by the Random
  245.   Iteration Algorithm.
  246.  
  247.  
  248. 5. Outline Editor Mode Operation
  249. --------------------------------
  250.  
  251. This is the mode you enter when you start IFS Lab; you can also re-enter it
  252. from the Collage Editor later by selecting the EDIT OUTLINE menuitem.
  253.  
  254. In this mode, you get a 320x200 screen with a gadget strip at the right and a
  255. drawing window for sketching your outline. The top four gadgets are mutually
  256. exclusive. The selected one (framed in red) defines your Drawing Mode:
  257.  
  258. - FREE is Freestyle Drawing - you press the left mouse button to draw.
  259. - LINE allows you draw straight lines by dragging the mouse.
  260. - XXX (Erase) turns the mouse into a 5x5 pixel eraser.
  261. - FILL allows you to flood-fill areas of your outline by clicking inside the
  262.   closed contour you wish to fill.
  263.  
  264. - The CLR gadget clears (erases) the entire outline.
  265. - The DONE gadget will end the Outline editing session and enter the Collage
  266.   Editor. If you haven't drawn anything and you click DONE, a "Default Outline"
  267.   (Happy Face) will be drawn automatically before entering the Collage Editor.
  268.  
  269.  
  270. The following Menu items are active in Outline Editor mode:
  271.  
  272. - PROJECT Menu:
  273.    NEW - Erases Outline, reverts to startup condition.
  274.    LOAD FILE - OUTLINE - Loads an outline from an IFF disk file (see section 7)
  275.              - IFS - Forces an exit to Collage mode, loads an IFS code from a
  276.                  disk file and Optimizes it (see below).
  277.              - IMAGE - Loads an Image from IFF file. The image screen remains
  278.                  in front until you click in it to push it back.
  279.    SAVE FILE - IMAGE - Saves the current Image, if any, to an IFF disk file.
  280.    QUIT - Exits program.
  281.  
  282. - DISPLAY Menu:
  283.    SHOW IMAGE - brings the image screen, if one exists, to the front.
  284.  
  285. - ABOUT Menu:
  286.    IFS THEORY, HELP, AUTHOR - Opens text screen, displays the appropriate info.
  287.    DEMO - Launches a demo of generation of the Sierpinski Triangle.
  288.  
  289. IMPORTANT:  the more pixels you draw in the Outline, the longer it will take
  290. the Collage Editor to compute the transformed images; so don't over-elaborate.
  291. It is probably best to avoid Area Fills altogether.
  292.  
  293.  
  294. 6. Collage Editor Mode Operation
  295. --------------------------------
  296.  
  297. You enter this mode after you've drawn your outline, and clicked the DONE
  298. gadget. Your objective now is to cover the Outline with transformed images
  299. of itself ("Pieces") until it is fully covered.
  300.  
  301. The Outline is displayed in white on a black background.  The collage is built
  302. up by adding Pieces - transformed images of the Outline - one by one, and
  303. manipulating them about the screen.  At any time one Piece is "Selected", and
  304. it is this Piece (and its transformation) that the user can manipulate.  The
  305. selected Piece is shown on the screen in red whereas all deselected Pieces are
  306. green.  The Selected Piece is accompanied by a corresponding Khaki-coloured
  307. vector diagram (see below).
  308.  
  309. - Creating a Piece:
  310.  
  311. a. The Default Piece is a half-sized copy of the Outline, placed in midscreen.
  312. b. This Default piece is created automatically on entry to Collage Editor mode.
  313. c. The Default Piece is also created when the user attempts to delete all
  314.    existing Pieces.
  315. d. A new Default Piece can be created by clicking the ADD gadget.
  316. e. A new Piece can be made in the same shape as the currently Selected 
  317.    Piece, by clicking the DUP gadget (it will then overlap the parent piece,
  318.    until it is modified or dragged off it).
  319.  
  320. - Selecting a Piece:
  321.  
  322. a. A newly created Piece is made Selected on creation.
  323. b. The user can change the current Selection by clicking the SEL gadget. 
  324.    This will make the selected piece advance backwards cyclically.
  325. c. On loading an IFS from file, the last Piece in the file is Selected.
  326.  
  327. - Deleting a Piece:
  328.  
  329. a. Clicking the DEL gadget will cause the Selected Piece to be deleted,
  330.    and it will disappear from the display.
  331. b. When a Piece is thus deleted, the next Piece will become Selected.
  332. c. If the user deletes the last remaining Piece, or if the CLR gadget is
  333.    clicked (deleting all pieces), the Default Piece will be created.
  334.  
  335. - Manipulating a Piece with the Mouse:
  336.  
  337. a. The Selected piece can be modified in a number of ways, covering all
  338.    possible affine transformations. Consider a cartesian coordinate system
  339.    denoted by unit vectors e1, e2 on the x and y axes respectively, with
  340.    lengths s1 = 1, s2 = 1 and angles r1 = 0, r2 = 0 relative to the
  341.    respective axes.  Then in the general case, any affine transformation can
  342.    be described by its effect on e1 and e2, i.e.  by what it does to change
  343.    s1, s2, r1 and r2 as it operates on the unit vectors, and in addition by
  344.    its translation of the Origin, denoted by t1, t2 in the x and y directions
  345.    respectively.  Note that the matrix coefficients commonly used to define
  346.    an affine transformation, denoted by a,b,c,d,e,f, are an alternative way
  347.    to describe the transformation; e and f are identical with t1 and t2,
  348.    while a,b,c,d can be derived from s1,s2,r1,r2 (and vice versa) by simple
  349.    formulas.
  350. b. The user-defined transformations in this program consist of combinations of
  351.    the following manipulations:
  352.       * Drag [Moves the Origin without affecting shape and orientation].
  353.       * Define e1 [Sets the endpoint of e1 by setting s1, r1].
  354.       * Define e2 [Sets the endpoint of e2 by setting s2, r2].
  355.       * Size [Changes the lengths s1 AND s2, leaving their ratio intact].
  356.       * Rotate [ Changes r1 AND r2 simultaneously by the same amount].
  357.  
  358.     The first three manipulations suffice to define any transformation; the
  359.     last two are provided for the user's convenience.
  360.  
  361. c. You are able to apply the manipulations to the Selected Piece by
  362.    manipulating with the mouse a construct called a Vector Box Diagram. This is
  363.    a parallelogram that represents the transformation of the Piece by showing
  364.    the image under this transformation of the rectangular frame of the
  365.    drawing area on the Outline window. The Origin is denoted by a small
  366.    square bearing the letter O at one corner of the parallelogram; similarly
  367.    the ends of the (transformed) X and Y axes are denoted by the letters 
  368.    X and Y, and the last corner by a solid square. You are able to click and
  369.    drag any corner of this Box, effecting the following changes in the
  370.    Transformation:
  371.  
  372.     * Drag - By dragging the Origin corner of the Box.
  373.     * Define e1, Define e2 - By dragging the corner corresponding to the
  374.       end of the chosen unit vector.
  375.     * Size/Rotate - By dragging the corner opposite the Origin corner.
  376.       Dragging it away from the origin corner or towards it will change Box
  377.       size; dragging it laterally will rotate the Box about the Origin corner.
  378.       A combination of both will achieve the combined effect.
  379.  
  380.     As you drag a corner, a second image of the Box will appear, in
  381.     ghosted lines, and will move and deform to show the effect of the dragging.
  382.     After you release the corner, the solid Box will move to the new
  383.     location/form and the appropriate deformation of the red image of the Piece
  384.     will be computed and displayed.
  385.  
  386. - Modifying a Piece's coefficient values from the Keyboard:
  387.  
  388. a. The coefficients a-f, the probability parameters Dens and p, and the
  389.    geometric parameters (s1,s2,r1,r2,t1,t2) corresponding to the Selected
  390.    Transformation can be viewed and manipulated directly by clicking the
  391.    NUM gadget. This action brings up a small draggable window with these
  392.    fourteen parameters shown in string gadgets, and with a Boolean ENTER 
  393.    gadget and a Close gadget. When this window is open, the menu of the main
  394.    Collage window is disabled but its gadgets remain active. The Vector Box
  395.    remains drawn but is inactive.
  396. b. You can modify any parameter from the keyboard by clicking in its
  397.    string gadget and inputting the value. Since some of these numbers are
  398.    interdependent, the other values will be recomputed as appropriate when 
  399.    you hit the Return key or select another string gadget.
  400. c. Changing the numbers in the Coefficients window will not affect the Piece
  401.    in the collage image until the ENTER gadget is clicked. At that time the
  402.    values in the string gadgets are read into the program's variables and the
  403.    image of the Piece, as well as its Vector Box, are redrawn accordingly.
  404. d. The ADD, DUP, SEL, DEL and CLR gadgets retain their usual functions,
  405.    and will cause the Coefficients window to update its contents to match the
  406.    newly selected Piece (which is also redrawn in the collage).  This allows
  407.    you to modify pieces successively from the Coefficients window, entering 
  408.    each change by using the ENTER gadget.
  409. e. You can Quit the Num Window (without modifying the piece) by clicking its
  410.    Window Close gadget.
  411.  
  412. - Definition of Piece Probabilities
  413.  
  414. a. Each Piece i has a probability, p(i), associated with it, which defines the
  415.    probability of that transformation being selected at any step in the
  416.    rendering process. The probabilities must satisfy  0 < p(i) < 1 for all i,
  417.    and their sum must be 1.
  418. b. In this program, the default is that all p(i) are set automatically to be
  419.    proportional to det(i) = |ad - bc|, the determinant of the transformation
  420.    matrix (except that if det(i)=0 then p(i) is set arbitrarily to 0.01). This
  421.    means that p(i) is proportional to the area of the image of each
  422.    transformation, giving equal pixel density across the full image during
  423.    rendering.
  424. c. To allow the user to meaningfully change the probabilities (which are all
  425.    interrelated by the constraint that their sum equal 1) we define another
  426.    parameter, Dens(i), the relative density the user wishes to force on a
  427.    Piece during rendering. The parameter Dens(i) is essentially the probability
  428.    per unit area of the Piece. If all Dens(i) equal 1 (the default), all pieces
  429.    retain equal density.  If the user sets Dens(k) > Dens(j), then piece k will
  430.    receive proportionately higher density than piece j. The probabilities are
  431.    computed to be:
  432.                  p(i) = Dens(i)*det(i) / sum [(Dens(i)*det(i)]
  433.  
  434.          with the sum extending over all currently defined pieces i.
  435.  
  436. d. When a new Piece is created, its Dens(i) is set to 1, its determinant
  437.    det(i) is computed from its matrix and its p(i) is computed as shown above,
  438.    as are all the other p(i) in the system.
  439.    (Note that when a Piece is DUPed, the new piece receives a density of 1,
  440.    regardless of the density of the mother Piece).
  441. e. When the user modifies (e.g. resizes) a Piece, its det(i) is recomputed
  442.    and all p(i) are recomputed.
  443. f. You may modify the density of a piece in the numeric entry window.
  444.    Whenever you do that, all p(i) are recomputed. The density thus set by you
  445.    will remain in effect through subsequent Piece modifications.
  446. g. In a SAVE IFS operation, only the p(i) are saved; during a LOAD IFS they
  447.    are read in and the det(i) and Dens(i) are computed and stored in memory.
  448.     [ det(i) = |ad-bc| unless this is zero, when it is set to 0.01;
  449.       Dens(i) = p(i)/det(i), since in a saved IFS file the sum of p(i) is 1 ].
  450.  
  451. - The Optimize function
  452.  
  453. a. The OPTIMIZE menu item performs two actions on the currently defined IFS:
  454.    First, it modifies its coefficients so that the Attractor of the IFS will
  455.    fill the full size of the window. Since this program uses no scaling or 
  456.    offset during Rendering but assumes instead that the Rendering window is 
  457.    of fixed size and location in the Real plane, this means modifying all the
  458.    e and f coefficients of the transformations.
  459. b. The second action is to create an Outline from the actual Attractor of the
  460.    IFS, and generate a Collage from this attractor. This will naturally be a
  461.    perfect Collage, as a result of the Collage Theorem.
  462.  
  463.  
  464. The following Menu items are active in Ouline Editor mode:
  465.   (NOTE: Menu system is disabled when Coefficients Window is displayed)
  466.  
  467. - PROJECT Menu:
  468.    NEW - Erases Outline & IFS, reverts to startup condition.
  469.    EDIT OUTLINE -  Erases IFS and enters Outline Editor mode.
  470.    LOAD FILE - OUTLINE - Clears the current IFS, enters the Outline Editor,
  471.                  and loads an outline from an IFF disk file (see section 7).
  472.              - IFS - loads an IFS code from a disk file and Optimizes it.
  473.              - IMAGE - Loads an Image from IFF file. The image screen remains
  474.                  in front until you click in it to push it back.
  475.    SAVE FILE - IFS - Saves the current IFS coefficients to a disk file.
  476.              - IMAGE - Saves the current Image, if any, to an IFF disk file.
  477.    OPTIMIZE - Executes the Optimize function (See above), adjusting the IFS
  478.                 so its attractor fills the Window, and generating its collage
  479.                 based on the Attractor as an Outline.
  480.    QUIT - Exits program.
  481.  
  482. - DISPLAY Menu:
  483.    SHOW CODES - Displays a table of the current IFS Code coefficients.
  484.    SHOW IMAGE - brings the image screen, if one exists, to the front.
  485.  
  486. - RENDER Menu:
  487.    RESOLUTION - Sets the screen resolution for the next Rendering operation.
  488.    GRAY LEVELS - Sets the number of Gray Levels to be used in rendering.
  489.    START - Initiates Rendering of the Attractor of the current IFS.
  490.  
  491. - ABOUT Menu:
  492.    IFS THEORY, HELP, AUTHOR - Opens text screen, displays the appropriate info.
  493.    DEMO - Launches a demo of generation of the Sierpinski Triangle.
  494.  
  495.  
  496. 7. Rendering Mode Operation
  497. ---------------------------
  498.  
  499. Rendering is initiated by the user in Collage Editor mode by the RENDER - START
  500. menu selection.  This causes the program to open the Image screen to the depth
  501. and resolution selected by the user via the RENDER menus (or the default, which
  502. is 640X400, 2 Gray Levels).  The program freezes all user interaction in the
  503. Collage Editor window (should the user bring it to front) and begins Rendering
  504. of the Fractal encoded by the current IFS, until the user clicks the mouse
  505. anywhere in the Image screen.  At that point the rendering stops and the Image
  506. screen remains in front until the user clicks in it again.  This second click
  507. causes the Image Screen to be pushed to the back and control is returned to the
  508. Collage Editor user interface.  You can later redisplay the Attractor by
  509. selecting the DISPLAY - SHOW IMAGE menu item.
  510.  
  511.  
  512. 8. File I/O Operation
  513. ---------------------
  514.  
  515. - Load Outline
  516.  
  517.    This reads in an ILBM IFF file and puts BITPLANE 0 of the image into the
  518.    Outline of the Outline Editor, ignoring the colours defined in the file.
  519.    Additional bitplanes are ignored; images larger than the window are cropped.
  520.  
  521. - Save IFS
  522.  
  523.    The saved IFS files are straight ASCII files. They list the transformation
  524.    coefficients a - f and p, as well as the additional information (which is
  525.    ignored by the IFS Load routine) of the density and the Geometrical scalings
  526.    and rotations of each transformation. Files are saved with the filename
  527.    extension .ifs (added to the filename if necessary by the program).
  528.  
  529. - Load IFS
  530.  
  531.  a. The IFS Code Loader routine is designed to read in IFS codes from
  532.    almost any ASCII file.  This permits it to read files generated by most
  533.    other IFS programs, regardless of their exact format.  The routine will
  534.    scan the file on a line by line basis, and will SKIP any line that does not
  535.    start with seven consecutive space-delimited numbers.  It will read in all
  536.    lines that DO so start, interpreting the seven numbers as the coefficients
  537.    a - f and the probability for one transformation.  Anything on such a line
  538.    after the seventh number is also ignored.  This means that all headers,
  539.    comments, and additional info (e.g.  colour information) is ignored.  If
  540.    the probabilities in the file seem to be cumulative (i.e.  the last one is
  541.    1.000) the program will convert them to the straight probabilities it needs.
  542.  
  543.  b. After reading in the IFS, the program checks whether its attractor will
  544.    fit in the window.  If not, it will modify the IFS coefficients so as to
  545.    make it fit.  This means that IFS codes previously saved by IFSLab will be
  546.    read in and not modified, but those generated by other programs - and hence
  547.    usually falling outside the window - will be converted to fit it properly.
  548.  
  549.  c. Finally, a Collage is generated from the attractor (this is an invocation
  550.    of the second part of the Optimize function) and displayed.
  551.  
  552. - Save Image
  553.  
  554.    This will save the contents of the Image Screen into an ILBM IFF file.
  555.  
  556. - Load Image
  557.  
  558.    This will load any ILBM IFF file, Open the Image Screen to the resolution
  559.    found in the file, and place the loaded image (including the colours) in
  560.    the Image Screen. This is a general IFF viewer; you can display any non-HAM
  561.    IFF file, even if it has nothing to do with IFS.  The image has no effect
  562.    on the IFS part of the program, it just stays in the Image Screen until you
  563.    render or load another image.
  564. ==========================
  565. Part III. Programmer Notes
  566. ==========================
  567.  
  568.  
  569. The following is intended for the benefit of those interested in writing IFS
  570. programs; it is not necessary for using IFS Lab.  It consists of various
  571. comments and technical notes related to the internal structure and function of
  572. the program, mostly accumulated during development.  Note that the source is
  573. included with the program for instruction rather than for compilation; to
  574. compile it you would need the IFF and req.library include and object module
  575. files, which are available in the public domain but are not included in this
  576. distribution.
  577.  
  578. 1. Coordinate system and Coefficient Ranges
  579. -------------------------------------------
  580.  
  581. a. Coordinate Convention: The Top Left corner of the display area is defined as
  582.   the Origin, (0,0), with the positive X axis going to the right and the 
  583.   positive Y axis going downward. The full display area is defined as 1 unit
  584.   in width and 0.6775 units in height (for purposes of the translation
  585.   coefficients). This convention makes the rectangular window used for editing
  586.   represent the top 2/3 (approximately) of a 1x1 square area in the Real plane.
  587.  
  588. b. Thus, the transformation  coefficients a -- d are all real numbers between
  589.   -1 and 1, as are the scalings s1, s2. Coefficients e, f, t1, and t2 are in
  590.   the range 0 -- 1. The angles r1, r2 are stored internally in radians in
  591.   the range -pi -- +pi, with positive angles denoting clockwise rotation. In
  592.   the Coefficients window, however, angles r1 and r2 are displayed in degrees,
  593.   between -180 and +180. The program will accept user entry into the
  594.   coefficients window of angles outside this range, and will convert them into
  595.   it.
  596.  
  597. 2. Screens and Windows
  598. ----------------------
  599.  
  600. The program uses the following screens and windows:
  601.  
  602. a. A low resolution, 4-bitplane (320X200) screen, with a GZZ Backdrop window
  603.    for Outline and Collage generation.
  604.    On this screen can also open the Coefficients Window: a narrow window with
  605.    fourteen string gadgets where the user can modify the Transformation
  606.    parameters.
  607.  
  608.   This screen is where the user interaction takes place; it opens when the
  609.   program is run and stays open throughout its operation.
  610.  
  611. b. A screen for rendering and displaying images, whose resolution and depth are
  612.   defined either when the user selects the rendering resolution, or by the ILBM
  613.   file bitmap header when an image is loaded from disk. This screen is opened
  614.   the first time that the user loads an image file or initiates rendering, and
  615.   stays open thereafter until the program is quit or until a new image file
  616.   load or render operation is initiated (when it is closed and re-opened to the
  617.   potentially different resolution of the new image). The image is displayed in
  618.   a GZZ Window in this screen.
  619.  
  620. c. A 640X200, 2-bitplane screen for Help and Codes table text display. This
  621.   screen is opened and then closed each time that the user selects a Help or
  622.   Show Codes menuitem. The text appears in a full-screen sized window that
  623.   obscures the screen depth gadgets.
  624.  
  625.  
  626. 3. Outline/Collage Window Colour Scheme
  627. ---------------------------------------
  628.  
  629. Window work area is black.
  630. Outline is drawn in white.
  631. Unselected Collage Pieces are green and the selected one is red.
  632. Vector Box is Khaki (except where it overlaps Outline and/or Pieces).
  633. Overlap of white and green is light green.
  634.  
  635. 0000  Black      Background         | 1000  Khaki    String Gadget borders
  636. 0001  Dk Green   Deselected Pieces  | 1001  Med Green   Coeff Window Text
  637.                  Menu Item Bgnd     |
  638. 0010  White      Outline            | 1010  Dk Green Box over Outline
  639. 0011  Lt Green   D.P. over Outline  | 1011  Dk Gray  Box over D.P. + Logo Bgnd
  640.                  Menu/Gadget Text   |
  641.                                     |
  642. 0100  Red        Selected Piece     | 1100  White    Complement Menu/Gadg Text
  643. 0101  Red        S.P. over Outline  | 1101  Dk Green Ghost Box over Outline
  644. 0110  Red        S.P. over D.P.     | 1110  Dk Gray  Complement Menu item Bgnd    
  645. 0111  Red        S.P. over D.P.     | 1111  Khaki    Complement to Boolean 
  646.                    over Outline     |                Gadget Bgnd; String Gadget
  647.                                     |                Cursor
  648.  
  649. 4. Gadget ID's
  650. --------------
  651.  
  652. GadgetID's:
  653.  
  654.   0        1    2     3    4      5    6   7   8   9      10    11   12  
  655. FREEHAND LINES ERASE FILL CLROUT DONE ADD DUP SEL DELETE CLRIFS NUM ENTER
  656.  
  657. Plus 14 coefficient string gadgets numbered 21 thru 34:
  658.  
  659.  a  -  f     Dens  p   s1  s2  r1  r2  t1  t2
  660. 21  - 26      27  28   29  30  31  32  33  34
  661.  
  662. There are also two inert dummy gadgets, one with image render and one with
  663. border render, tacked on to the end of the two gadget lists for the Editor
  664. Window - these are used to place the IFS-Lab logo at the lower right corner of
  665. the window, and make it immune to obliteration by the NUM window when it is
  666. dragged to the right.
  667.  
  668. 5. Outline Editor
  669. -----------------
  670.  
  671. The Fill function uses the graphic library function Flood() in mode 0, which
  672. fills to the enclosing outline. For some reason I couldn't make Flood() work in
  673. mode 1. The mode 0 fill ran into problems if the filled area touched the edge
  674. of the window in some cases. To solve this, I made the fix of enclosing the
  675. window drawing area in a 1-pixel-wide white border before calling Flood(),
  676. and repainting a black border after the Flood(). This does mean that if you use
  677. Fill, you can't use the outermost pixel around your window for the Outline
  678. drawing.
  679.  
  680. 6. Piece Storage
  681. ----------------
  682.  
  683. - Each Piece (Transformation) is stored as 2 entities:
  684.  
  685.   a. A piece structure denoting all coefficients needed to describe it (with
  686.     some redundancy), namely:
  687.  
  688.     double a, b, c, d, e, f   Matrix Coefficients
  689.     double s1,s2,r1,r2        Geometric coefficients
  690.     double dens, p            Probability and Density
  691.     double det                Determinant
  692.     UBYTE *piecemap        Pointer to the bitplane containing the piece's shape
  693.     struct pixel boxo, boxx, boxy, boxz
  694.  
  695.     The last 4 members are the corners of the Vector Box, in GZZ coordinates.
  696.     (struct pixel consists of x and y coordinates for a single pixel).
  697.  
  698.   b. A single bitplane in CHIP RAM containing the image of the Piece. The
  699.     bitplane is of size Window->Width X Window->GZZHeight pixels; it is
  700.     equivalent to the (Full, not inner) Window minus its top and bottom
  701.     borders.
  702.  
  703. - There is an array of 20 pointers to piece structures, pieceptr[MAX_N + 1].
  704.   (The number 20 is coded as    #define MAX_N 19  ).
  705.  
  706. - The variable N stores the index of the highest existing Piece. That is,
  707.   pointers pieceptr[0] thru pieceptr[N] are used. Note that there are then 
  708.   N+1 Pieces, and that  N =< MAX_N.
  709.  
  710. - The variable selpiece stores the index of the currently selected Piece.
  711.  
  712. - The function AllocPiece() allocates memory for a piece structure and
  713.   bitplane (checking that memory is available); puts the bitplane pointer in 
  714.   the structure; and returns a pointer to the piece structure.
  715.  
  716. - The function FreePiece() takes a pointer to a piece structure and frees the
  717.   memory allocated to that structure and to the associated piecemap.
  718.  
  719. 7. Collage Display mechanics
  720. ----------------------------
  721.  - The 4 Bitplanes of the GZZ bitmap are dedicated to the different elements
  722.    of the Collage as follows:
  723.  
  724.  * Plane 0 - Deselected Pieces
  725.  * Plane 1 - Outline
  726.  * Plane 2 - Selected Piece
  727.  * Plane 3 - Vector Box
  728.  
  729.  * On entering Collage mode, bitplane 1 is copied to a buffer (pointed at
  730.    by outlinebufptr), which serves as a source for TransformPiece(). This is
  731.    needed because when the coefficients window is displayed, Plane 1 cannot be
  732.    used as a contiguous source for the outline.
  733.  
  734. - The DrawCollage() function recreates the display as follows:
  735.  
  736.  * Erase bitplanes 0,2,3 (leaving the Outline intact).
  737.  * Blit all Deselected Pieces from their piecemaps to Bitplane 0.
  738.  * Blit the currently Selected Piece from its piecemap to Bitplane 2.
  739.  * Draw the currently Selected  Piece's Vector Box in Bitplane 3 by calling
  740.    DrawBox().
  741.  
  742. - The TransformPiece() function takes pointers to a source bitplane and
  743.   a destination piecemap bitplane, and executes the affine transformation
  744.   given in a piece structure pointed at by its third argument to map the
  745.   source into the destination. If a transformed pixel falls outside the
  746.   destination boundary, it is not written, and the function aborts (leaving 
  747.   the destination piecemap trashed) and returns 0; else it returns 1. The
  748.   function skips the source bitplane's top and bottom borders. Use of Integer
  749.   math has speeded up this function by a factor of 2.7X relative to FFP.
  750.  
  751. - The DrawBox() function erases Bitplane 3, then draws the Vector Box of the 
  752.   currently Selected Piece in Bitplane 3 using the graphics drawing routines, 
  753.   after write-protecting Bitplanes 0,1,2 in the Rastport mask.
  754.  
  755. - Modifying the shape of the Selected Piece is done by manipulating its 
  756.   piecemap and Bitplane 2, without affecting the other Bitplanes:
  757.  
  758.  * User tells program to change shape or position of Piece, using the Vector
  759.    Box. 
  760.  * On releasing the mouse button on the vector box, program computes the
  761.    transformed piece image using the Outline buffer as source and putting the
  762.    transformed image in the Piecemap of that Piece.
  763.  * Before each Pixel is written into the destination, it is checked for
  764.    overflow beyond bitmap boundary. If overflow is found, program notifies
  765.    user, cancels the operation, and restores the piecemap by copying the
  766.    unmodified image from Plane 2 to the piecemap (if Coefficients window is
  767.    displayed, the restoration is by re-transforming the outline as plane 2 is
  768.    interfered with by the coefficients window).
  769.  * If no overflow is met, program blits the transformed piece from piecemap to
  770.    Plane 2, and updates the piece structure.
  771.  * Vector Box is restored to its Old / New shape depending on whether overflow
  772.    has been found or not.
  773.  
  774. 8. Coefficients Window issues
  775. -----------------------------
  776.  
  777. - Modifying the number in any string gadget requires changing the values of
  778.   other coefficients. This is handled by RecomputeCoeffs() which
  779.   re-calculates the necessary coefficients based on the one just modified,
  780.   which is specified as its parameter. The modified coefficients are placed
  781.   in the string gadget buffers, and are then shown in the display by a call
  782.   to RefreshGadgets(). This happens when the user presses CR after the entry
  783.   in the gadget (a GADGETUP event), or (failing that) when the next gadget is
  784.   selected (a GADGETDOWN event). This redraws the gadgets' contents. However,
  785.   there is a problem if a gadget is refreshed while the left mouse button is
  786.   still pressed within it. To prevent that, the refresh following a
  787.   GADGETDOWN event is done gadget by gadget [ using RefreshGList() ] and
  788.   skips the last-hit gadget.
  789.  
  790. - RecomputeCoeffs() also checks that all coefficients currently in the string
  791.   gadgets are in their legal ranges. If not, it restores the illegal
  792.   coefficient to its previous value, stored in the selected piece's structure.
  793.  
  794. - numgadgpending holds the gadget ID of the string gadget currently under
  795.   modification, i.e. the last one selected and not yet terminated by a CR or
  796.   by selecting a subsequent gadget. It is set to -1 if no gadget is pending.
  797.  
  798. - UpdateNumStrings() loads the coefficients from the Selected piece's structure
  799.   into the string gadgets.
  800.  
  801. - Clicking the ENTER Gadget causes a recomputation of coefficients if needed
  802.   (On GADGETDOWN) and then on GADGETUP executes the transformation specified
  803.   by the coefficients in the string gadgets, with a check for piece overflow,
  804.   and displays the transformed piece and its new Vector Box.
  805.  
  806. 9. Rendering Mechanics
  807. ----------------------
  808.  
  809. - Function RenderImage() calls OpenImageScreen(), which opens the screen as
  810.   well as the Backdrop, GZZ Image Window in it (Backdrop used so its title bar
  811.   can be placed behing the screen's, leaving the screen depth gadgets visible).
  812.   The screen colours are bluish,selected to minimize flicker in Interlace mode.
  813.  
  814. - In the rendering loop, a random number is compared to the cumulative
  815.   probabilities of the transformations and the first one to exceed it sets the
  816.   transformation to be used; this is applied to the previous iteration's pixel
  817.   and the resultant new pixel is drawn in the window (in 2-gray-level mode) or
  818.   incremented one gray level (in a multiple gray level mode).
  819.  
  820. - Significant speed-up of rendering (40%) has been achieved by using integer
  821.   math for transformation and probability computations. The coefficients a--f
  822.   are converted in RenderImage(): they are scaled by multiplication by a
  823.   million, and converted to long integers. All math is done in these integers,
  824.   and the result divided by a million to get the next pixel coordinates. The
  825.   Cumulative probabilities are also scaled by RAND_MAX (the top limit of the
  826.   random number generator) and converted to integer, and compared directly to
  827.   the generator's integer output later on. (The Manx integer random generator,
  828.   rand(), is much faster than the floating point generator ran()).
  829.  
  830. - Pixels are drawn using WritePixel(); direct write into the window's
  831.   bitplane achieved negligible speed-up here and was abandoned.
  832.  
  833. - After each pixel is drawn, the ImageWindow IDCMP is examined for a
  834.   mouseclick indicating "stop rendering". When this is detected rendering stops
  835.   and upon a further mouseclick the Image screen is pushed back and the collage
  836.   screen placed up front.
  837.  
  838. 10. Compilation and Linking
  839. ---------------------------
  840. IFSLab was developed under AmigaDOS 1.2, on an Amiga 2000.  It has been tested
  841. on Amigas 500, 2000 and 3000 and under AmigaDOS 1.2, 1.3 and 2.0.
  842.  
  843. This program uses the file requester in the Fox/Dawson requester library,
  844. req.library, which should be present in your libs:  directory (otherwise, file
  845. I/O will be disabled).
  846.  
  847. Compile with Aztec C 5.0, with -ff option (Fast floating point) and -safmnpsu
  848. options (code optimization). Link with +cd option (forces sprite and image data
  849. to load in CHIP RAM).  Link with IFF files (from CBM IFF Disk, Fish disk #185),
  850. and with the gluecode module for the Fox/Dawson requester library, thus:
  851.  
  852. cc  -ff -safmnpsu -i IFF -i req IFSLab.c
  853. ln +cd IFSLab.o IFF/putpict.o IFF/ilbmw.o IFF/packer.o IFF/iffw.o
  854.   IFF/readpict.o IFF/ilbmr.o IFF/unpacker.o IFF/iffr.o IFF/remalloc.o
  855.   req/myreqglue.o  mf.lib c.lib
  856.  
  857. Note that the IFF files on the CBM IFF disk require some fixing to actually
  858. work under Aztec C.
  859.  
  860. 11. Known Bugs
  861. --------------
  862.  
  863. So far, two obscure bugs have been observed:
  864.  
  865. a. If Mungwall is run before executing IFSLab,a system crash will occur halfway
  866.   through execution of the Demo function.  Attempts to trace this bug place it
  867.   in a call to SetWindowTitles() from inside SetMode(), which is very puzzling
  868.   (SetMode() works fine elsewhere in IFSLab).  This bug is not solved; however,
  869.   it has never been observed while testing IFSLab on a number of Amigas WITHOUT
  870.   Mungwall.  Hopefully you will not ever encounter it.
  871.  
  872. b. UNLESS the -safmnpsu option is used when compiling, the program will crash 
  873.   when a Save Image operation is attempted. Using these -s options solved this
  874.   problem; thus this bug is not present in the executable supplied.
  875.